package com.buaa.homework02;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class MainActivity extends AppCompatActivity {

    private EditText address2;

    Handler handler = new Handler(){

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        address2 = (EditText)findViewById(R.id.address2);
    }

    public void getAddress(View view) {

        Intent intent = new Intent("address");
        startActivityForResult(intent,1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==1 && resultCode==1) {
            String address = data.getStringExtra("address");
            address2.setText(address);
        }
    }

    public void submit(View view) {

        try {
            OutputStream out = new FileOutputStream("/sdcard/data.db");
            out.write();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
